use ::libc;
extern "C" {
    fn __errno_location() -> *mut i32;
    fn vsnprintf(
        _: *mut i8,
        _: u64,
        _: *const i8,
        _: ::core::ffi::VaList,
    ) -> i32;
    fn vasprintf(
        __ptr: *mut *mut i8,
        __f: *const i8,
        __arg: ::core::ffi::VaList,
    ) -> i32;
    fn malloc(_: u64) -> *mut libc::c_void;
    fn calloc(_: u64, _: u64) -> *mut libc::c_void;
    fn reallocarray(__ptr: *mut libc::c_void, __nmemb: size_t, __size: size_t)
        -> *mut libc::c_void;
    fn strndup(_: *const i8, _: u64) -> *mut i8;
    fn strerror(_: i32) -> *mut i8;
    fn strdup(_: *const i8) -> *mut i8;
    fn recallocarray(_: *mut libc::c_void, _: size_t, _: size_t, _: size_t) -> *mut libc::c_void;
    fn fatalx(_: *const i8, _: ...) -> !;
}
pub type __builtin_va_list = [__va_list_tag; 1];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct __va_list_tag {
    pub gp_offset: u32,
    pub fp_offset: u32,
    pub overflow_arg_area: *mut libc::c_void,
    pub reg_save_area: *mut libc::c_void,
}
pub type size_t = u64;
pub type va_list = __builtin_va_list;
#[no_mangle]
pub unsafe extern "C" fn xmalloc(mut size: size_t) -> *mut libc::c_void {
    let mut ptr: *mut libc::c_void = std::ptr::null_mut::<libc::c_void>();
    if size == 0 as i32 as u64 {
        fatalx(b"xmalloc: zero size\0" as *const u8 as *const i8);
    }
    ptr = malloc(size);
    if ptr.is_null() {
        fatalx(
            b"xmalloc: allocating %zu bytes: %s\0" as *const u8 as *const i8,
            size,
            strerror(*__errno_location()),
        );
    }
    return ptr;
}
#[no_mangle]
pub unsafe extern "C" fn xcalloc(mut nmemb: size_t, mut size: size_t) -> *mut libc::c_void {
    let mut ptr: *mut libc::c_void = std::ptr::null_mut::<libc::c_void>();
    if size == 0 as i32 as u64 || nmemb == 0 as i32 as u64 {
        fatalx(b"xcalloc: zero size\0" as *const u8 as *const i8);
    }
    ptr = calloc(nmemb, size);
    if ptr.is_null() {
        fatalx(
            b"xcalloc: allocating %zu * %zu bytes: %s\0" as *const u8 as *const i8,
            nmemb,
            size,
            strerror(*__errno_location()),
        );
    }
    return ptr;
}
#[no_mangle]
pub unsafe extern "C" fn xrealloc(
    mut ptr: *mut libc::c_void,
    mut size: size_t,
) -> *mut libc::c_void {
    return xreallocarray(ptr, 1 as i32 as size_t, size);
}
#[no_mangle]
pub unsafe extern "C" fn xreallocarray(
    mut ptr: *mut libc::c_void,
    mut nmemb: size_t,
    mut size: size_t,
) -> *mut libc::c_void {
    let mut new_ptr: *mut libc::c_void = std::ptr::null_mut::<libc::c_void>();
    if nmemb == 0 as i32 as u64 || size == 0 as i32 as u64 {
        fatalx(b"xreallocarray: zero size\0" as *const u8 as *const i8);
    }
    new_ptr = reallocarray(ptr, nmemb, size);
    if new_ptr.is_null() {
        fatalx(
            b"xreallocarray: allocating %zu * %zu bytes: %s\0" as *const u8 as *const i8,
            nmemb,
            size,
            strerror(*__errno_location()),
        );
    }
    return new_ptr;
}
#[no_mangle]
pub unsafe extern "C" fn xrecallocarray(
    mut ptr: *mut libc::c_void,
    mut oldnmemb: size_t,
    mut nmemb: size_t,
    mut size: size_t,
) -> *mut libc::c_void {
    let mut new_ptr: *mut libc::c_void = std::ptr::null_mut::<libc::c_void>();
    if nmemb == 0 as i32 as u64 || size == 0 as i32 as u64 {
        fatalx(b"xrecallocarray: zero size\0" as *const u8 as *const i8);
    }
    new_ptr = recallocarray(ptr, oldnmemb, nmemb, size);
    if new_ptr.is_null() {
        fatalx(
            b"xrecallocarray: allocating %zu * %zu bytes: %s\0" as *const u8 as *const i8,
            nmemb,
            size,
            strerror(*__errno_location()),
        );
    }
    return new_ptr;
}
#[no_mangle]
pub unsafe extern "C" fn xstrdup(mut str: *const i8) -> *mut i8 {
    let mut cp: *mut i8 = std::ptr::null_mut::<i8>();
    cp = strdup(str);
    if cp.is_null() {
        fatalx(
            b"xstrdup: %s\0" as *const u8 as *const i8,
            strerror(*__errno_location()),
        );
    }
    return cp;
}
#[no_mangle]
pub unsafe extern "C" fn xstrndup(
    mut str: *const i8,
    mut maxlen: size_t,
) -> *mut i8 {
    let mut cp: *mut i8 = std::ptr::null_mut::<i8>();
    cp = strndup(str, maxlen);
    if cp.is_null() {
        fatalx(
            b"xstrndup: %s\0" as *const u8 as *const i8,
            strerror(*__errno_location()),
        );
    }
    return cp;
}
#[no_mangle]
pub unsafe extern "C" fn xasprintf(
    mut ret: *mut *mut i8,
    mut fmt: *const i8,
    mut args: ...
) -> i32 {
    let mut ap: ::core::ffi::VaListImpl;
    let mut i: i32 = 0;
    ap = args.clone();
    i = xvasprintf(ret, fmt, ap.as_va_list());
    return i;
}
#[no_mangle]
pub unsafe extern "C" fn xvasprintf(
    mut ret: *mut *mut i8,
    mut fmt: *const i8,
    mut ap: ::core::ffi::VaList,
) -> i32 {
    let mut i: i32 = 0;
    i = vasprintf(ret, fmt, ap.as_va_list());
    if i == -(1 as i32) {
        fatalx(
            b"xasprintf: %s\0" as *const u8 as *const i8,
            strerror(*__errno_location()),
        );
    }
    return i;
}
#[no_mangle]
pub unsafe extern "C" fn xsnprintf(
    mut str: *mut i8,
    mut len: size_t,
    mut fmt: *const i8,
    mut args: ...
) -> i32 {
    let mut ap: ::core::ffi::VaListImpl;
    let mut i: i32 = 0;
    ap = args.clone();
    i = xvsnprintf(str, len, fmt, ap.as_va_list());
    return i;
}
#[no_mangle]
pub unsafe extern "C" fn xvsnprintf(
    mut str: *mut i8,
    mut len: size_t,
    mut fmt: *const i8,
    mut ap: ::core::ffi::VaList,
) -> i32 {
    let mut i: i32 = 0;
    if len > 2147483647 as i32 as u64 {
        fatalx(b"xsnprintf: len > INT_MAX\0" as *const u8 as *const i8);
    }
    i = vsnprintf(str, len, fmt, ap.as_va_list());
    if i < 0 as i32 || i >= len as i32 {
        fatalx(b"xsnprintf: overflow\0" as *const u8 as *const i8);
    }
    return i;
}
